$(function () {
    isLogon();
});

function isLogon() {
    // let boo = sessionStorage.getItem("username") == null;
    // if (boo) {
    //     alert("你为登录，即将跳转登录页面");
    //     window.open("/html/login.html");
    //     return false;
    // }
    findAll();
}

function findAll() {
    let result = myAjax("/back/product/findAll", {}, "get");
    setData(result.list);
}

function setData(data) {
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += '<div>\n' +
            '            <div>' + data[i].id + '</div>\n' +
            '            <div>' + getUndefined(data[i].productName) + '</div>\n' +

            '            <div>' + getUndefined(data[i].normalPrice) + '</div>\n' +
            '            <div>' + getUndefined(data[i].marketPrice) + '</div>\n' +
            // '            <div>' + data[i].content + '</div>\n' +
            '            <div><img src="' + getUndefined(data[i].imgHref) + '"  style="width: 30px;height: 30px"></div>\n' +
            '            <div>' + (data[i].enable == 1 ? "正常" : "异常") + '</div>\n' +
            '            <div>\n' +
            '                <div onclick="toEditPage(' + data[i].id + ')"><i class="iconfont icon-xxx">&#xe626;</i></div>\n' +
            '                <div onclick="del(' + data[i].id + ')"><i class="iconfont icon-xxx">&#xe624;</i></div>\n' +
            '                <div onclick="editPassword(' + data[i].id + ')"><i class="iconfont icon-xxx">&#xe61e;</i></div>\n' +
            '            </div>\n' +
            '        </div>';
    }
    $(".my-body").html(html);
}

function getUndefined(value) {
    return value == 'undefined' || value == 'null' || value == null ? '' : value;
}

function toEditPage(id) {
    sessionStorage.setItem("productId", id);
    openWindow("/html/back/product/productEdit.html");
}